package com.zb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zb.dto.LoginUser;
import com.zb.entity.TbAdminModel;
import com.zb.service.TbAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailServiceImpl implements UserDetailsService {

    @Autowired
    private TbAdminService adminService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        LambdaQueryWrapper<TbAdminModel> qw = new LambdaQueryWrapper<>();
        qw.eq(TbAdminModel::getLoginName, username);
        TbAdminModel adminModel = adminService.getOne(qw);
        return new LoginUser(adminModel);
    }
}
